// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CResolvedItem.
//   $Id$

#pragma once


class CResolvedItemList;
//<summary>stores the label/value pair for an item</summary>
//<remarks>
//	The actual values, either returned from XPath queries, or
//	as inline content in an item are stored here.
//	There is a direct 1-1 mapping of this class to an item object.
//	An itemset object, (with either value or copy)
//	will contain a list of them, corresponding to the size of the nodest.
//	A choices object will have 1 and a list (itself and its children).
//	and a selection will have a list.
//</remarks>
class CResolvedItem
{
public:
	CResolvedItem(CResolvedItemList * pOwnerList);
	~CResolvedItem(void);
	// stores a string as the resolved value for this item
	HRESULT put_value(BSTR sValue);
	// stores a node as the resolved value for this item
	HRESULT put_value(IXMLDOMNode * pNode);
	//<summary> stores a ResolvedItemlist as the resolved value for this item,</summary>
	//<remarks>this would be bound to choices</remarks>
	HRESULT put_value(CResolvedItemList* pList);
	// <summary>retrieves a copy of the underlying resolved value.</summary>
	//<returns>S_FALSE if there is no value, otherwise S_OK</returns>
	HRESULT get_value(VARIANT * pvtRetVal);
	HRESULT put_label(BSTR s);
	//selects this item.
	//<param name="bFireEvent">
	//	if the item has been programmatically selected
	//	by the user, it may be desired that the xforms-selected
	//	event is not fired.
	//</param>
	HRESULT select(bool bFireEvent = true);
	//deselects this item.
	//<param name="bFireEvent">
	//	if the item has been programmatically selected
	//	by the user, it may be desired that the xforms-selected
	//	event is not fired.
	//</param>
	HRESULT deselect(bool bFireEvent = true);
	long m_lId;
private:
	bool m_bIsCurrentlySelected;
	//<summary> The actual resolved label.</summary>
	CComBSTR m_sLabel;
	// called by the put_value functions to properly clear the current value and free any associated memory.
	void emptyCurrentValue(void);

	//<remarks>The value that this item points to, may be:
	// <list>
	//	<item>VT_BSTR: for items and itemsets</item>
	//	<item>VT_DISPATCH: containing an IXMLDOMNode for copy</item>
	//	<item>VT_I4: containing a pointer to a ResolveedItemList for choices</item>
	// </list>
	//<remarks>
	VARIANT m_vtVal;
	//<summary>a pointer to the list that owns this item.</summary>
	CResolvedItemList * m_pList;
};
